package com.zr.action;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.Map;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.struts2.interceptor.ServletRequestAware;
import org.apache.struts2.interceptor.ServletResponseAware;
import org.apache.struts2.interceptor.SessionAware;

import com.opensymphony.xwork2.ActionSupport;
import com.zr.model.Cuser;
import com.zr.service.ShowMyInfoService;

import net.sf.json.JSONObject;
/**
 * 
 * @author HC
 *
 */
public class ShowMyInfoAction extends ActionSupport implements ServletResponseAware,ServletRequestAware,SessionAware{
	 private HttpServletResponse resp;
	 private  Map<String,Object> session; 
	 private HttpServletRequest req;	

	 @Resource
	 private ShowMyInfoService showMyInfoService;
	 
	@Override
	public void setSession(Map<String, Object> session) {
		this.session = session;
	}

	@Override
	public void setServletResponse(HttpServletResponse response) {
		this.resp = response;
	}
	
	@Override
	public void setServletRequest(HttpServletRequest request) {
		this.req = request;
	}
	
	public void showMyInfo(){
		resp.setCharacterEncoding("utf8");
		Cuser u = (Cuser)session.get("cuser");
		int page = Integer.parseInt(req.getParameter("page"));
	    int rows = Integer.parseInt(req.getParameter("rows"));
		int uid = u.getUid();
		JSONObject us = new JSONObject();
		us = showMyInfoService.getMyInfo(uid, page, rows);
		try {
			PrintWriter pw = resp.getWriter();
			pw.write(us.toString());
		} catch (IOException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
	
}
